package com.project.servlet;

import com.project.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller("test")
public class TestServlet extends HttpServlet {
    @Autowired
    private IUserService service;
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置响应信息的MIME类型和编码集
        resp.setContentType("text/html;charset=utf-8");
        //向客户端输出信息
        resp.getWriter().print("hello,中国 " + service.getUserName());
    }
}
